package orest.front.achieve;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;





import net.ssta.common.Constants;
import net.ssta.core.base.ServletBase;
import net.ssta.core.db.PagingInfo;
import net.ssta.core.db.RecordSet;
import net.ssta.core.db.Record;
import net.ssta.core.web.RequestKit;

public class AchieveServlet extends ServletBase {

	protected void defaultAction(HttpServletRequest request, HttpServletResponse response) throws IOException
	{
			System.out.println("UserNeedsServlet default Action");
	}
	
     
    /**
     * test
     *  
     * @param request
     * @param response
     */
    public void testFillTable(HttpServletRequest request,
        HttpServletResponse response)
    {
        try
        {
        	AchieveHandler unhandler = new AchieveHandler();
            RecordSet rset = unhandler.testFillTable();
            
            appendString(rset.getJsonString());
        }
        catch (Exception e)
        {
        	e.printStackTrace();
        }
    }
    
    /**
     * test
     *  科技成果列表
     * @param request
     * @param response
     */
    public void getKjcgById(HttpServletRequest request,
        HttpServletResponse response)
    {
        try
        {
        	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        	String kjcgid = requestKit.getParameter("kjcgid", "");
        	AchieveHandler handler = new AchieveHandler();
            Record record = handler.getKjcgById(kjcgid);
            
            appendString(record.getJsonString());
        }
        catch (Exception e)
        {
        	e.printStackTrace();
        }
    }
    
    
    /**
     * test
     *  科技成果列表
     * @param request
     * @param response
     */
    public void getKjcgList(HttpServletRequest request,
        HttpServletResponse response)
    {
        try
        {
        	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        	AchieveHandler handler = new AchieveHandler();
            RecordSet rset = handler.getKjcgList(requestKit);
            
            appendString(rset.getJsonString());
        }
        catch (Exception e)
        {
        	e.printStackTrace();
        }
    }
    
    
    /**
     * 
     * 通过父类别的optionValue获得T_FIELDOPTION表的所有子类别 
     * @param request
     * @param response
     */
    public void getSubFlByFatherOptValue(HttpServletRequest request,
        HttpServletResponse response)
    {
        try
        {
        	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        	AchieveHandler handler = new AchieveHandler();
            RecordSet rset = handler.getSubFlByFatherOptValue(requestKit);
            
            appendString(rset.getJsonString());
        }
        catch (Exception e)
        {
        	e.printStackTrace();
        }
    }
    
    
    
    
    
    
    /**
     * test
     *  获得推荐科技成果列表
     * @param request
     * @param response
     */
    public void getRecommendKjcgList(HttpServletRequest request,
        HttpServletResponse response)
    {
        try
        {
        	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        	AchieveHandler handler = new AchieveHandler();
            RecordSet rset = handler.getRecommendKjcgList(requestKit);
            AchieveHandler.getNewEnergyClassList();
            appendString(rset.getJsonString());
        }
        catch (Exception e)
        {
        	e.printStackTrace();
        }
    }
    
    
    /**
     * test
     *  获得新能源分类,分类可能是2级的,每个Record表示一个分类,如果record的CHILDLIST不为空,表示该分类有子分类，了分类也是一个RecordSet
     * @param request
     * @param response
     */
    public void getNewEnergyClassListJson(HttpServletRequest request,
        HttpServletResponse response)
    {
        try
        {
        	RequestKit requestKit = (RequestKit) request.getAttribute("RequestKit");
        	AchieveHandler handler = new AchieveHandler();
            RecordSet rset = handler.getNewEnergyClassList();
            appendString(rset.getJsonString());
        }
        catch (Exception e)
        {
        	e.printStackTrace();
        }
    }
    
    /**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		RecordSet rset = new RecordSet();
		Record record = new Record();
		record.addData("id", "1");
		record.addData("name", "                                                                       ");
		rset.add(record);
		record.addData("id", "2");
		record.addData("name", "1982年1月-2002年8月在山东轻工业学院工作，历任讲师，副教授，1997年起任教授；教研室主任，系主任。2002年9月在天津科技大学工作，任教授，博士生导师2000年起担任中国皮革科技委员会副主任                    ");
		rset.add(record);
		System.out.println(rset.getJsonString());
	}
    
}
